#include "stdafx.h"
#include "win_result.h"

_SSL_BEGIN
_SSWINOSL_BEGIN


bool result_get_description(
	ss_in_ DWORD err_code,
	ss_out_ tstring &descript,
	ss_in_ ss_optional_ DWORD lang_id /*= 0*/,
	ss_in_ ss_optional_ HANDLE res_module /*= NULL*/
	)
{
	DWORD flags = FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_ALLOCATE_BUFFER;
	if(res_module != NULL)
		flags |= FORMAT_MESSAGE_FROM_HMODULE;
	else
		flags |= FORMAT_MESSAGE_FROM_SYSTEM;

	HLOCAL local_handle = NULL;
	if(!::FormatMessage(
		flags,
		res_module,
		err_code,
		lang_id,
		(PTSTR)&local_handle,
		0,
		NULL))
	{
		return false;
	}

	descript = (PCTSTR)LocalLock(local_handle);

	::LocalFree(local_handle);
	local_handle = NULL;

	return true;
}

_SSWINOSL_END
_SSL_END

